﻿Imports Equipment.DataAccess
Imports System.Text

Public Class PageAccess

#Region "Properties"
    Public Grant As Boolean
    Public Type As PageType
    Public Description As String
#End Region

    Public Shared Function RetrieveAll() As List(Of PageAccess)
        Dim result As New List(Of PageAccess)

        result.Add(New PageAccess With {.Grant = False, .Type = PageType.AssetType, .Description = "Software Configuration - Asset Type"})
        result.Add(New PageAccess With {.Grant = False, .Type = PageType.SitesDepartmentSetup, .Description = "Software Configuration - Sites and Department Setup"})
        result.Add(New PageAccess With {.Grant = False, .Type = PageType.HolidayDefinition, .Description = "Software Configuration - Holiday Definition"})
        result.Add(New PageAccess With {.Grant = False, .Type = PageType.NotificationType, .Description = "Software Configuration - Notification Types"})
        result.Add(New PageAccess With {.Grant = False, .Type = PageType.UserGroup, .Description = "Software Configuration - User Groups"})
        result.Add(New PageAccess With {.Grant = False, .Type = PageType.UserRole, .Description = "Software Configuration - User Roles"})
        result.Add(New PageAccess With {.Grant = False, .Type = PageType.Users, .Description = "Software Configuration - Users"})
        result.Add(New PageAccess With {.Grant = False, .Type = PageType.BasicRequirementsSetup, .Description = "Software Configuration - Basic Requirements Setup"})
        result.Add(New PageAccess With {.Grant = False, .Type = PageType.Others, .Description = "Software Configuration - Others"})
        result.Add(New PageAccess With {.Grant = False, .Type = PageType.CreateWorkOrder, .Description = "Work Order - Create Work Order"})
        result.Add(New PageAccess With {.Grant = False, .Type = PageType.ManageWorkOrder, .Description = "Work Order - Manage Work Order"})
        result.Add(New PageAccess With {.Grant = False, .Type = PageType.ProcessWorkOrder, .Description = "Work Order - Process Work Order"})
        result.Add(New PageAccess With {.Grant = False, .Type = PageType.PostWorkOrder, .Description = "Work Order - Post Work Order"})
        result.Add(New PageAccess With {.Grant = False, .Type = PageType.ReviewWorkOrder, .Description = "Work Order - Review Work Order"})
        result.Add(New PageAccess With {.Grant = False, .Type = PageType.AssetMaintain, .Description = "Asset Management - Asset Main"})
        result.Add(New PageAccess With {.Grant = False, .Type = PageType.AssetCreate, .Description = "Asset Management - Create Asset"})
        result.Add(New PageAccess With {.Grant = False, .Type = PageType.AssetEdit, .Description = "Asset Management - Maintain Asset"})

        Return result
    End Function

    Public Shared Function RetrieveAllByStatusString(ByVal statusStr As String) As List(Of PageAccess)
        Dim result = RetrieveAll()

        If Not String.IsNullOrEmpty(statusStr) Then
            Dim strValues = statusStr.Split(";")

            For Each item In strValues
                Dim pair As String() = item.Split(":")
                If pair.Length > 1 Then
                    Dim pType As PageType = DirectCast(Integer.Parse(pair(0)), PageType)
                    Dim grand As Boolean = Boolean.Parse(pair(1))

                    Dim page = result.FirstOrDefault(Function(p) p.Type = pType)

                    If page IsNot Nothing Then
                        page.Grant = grand
                    End If
                End If
            Next

        End If


        Return result
    End Function

    Public Shared Function GetStatusStringByList(ByVal pageAccessList As List(Of PageAccess)) As String
        Dim str As New StringBuilder()

        For Each page As PageAccess In pageAccessList
            str.Append(String.Format("{0}:{1};", CInt(page.Type), page.Grant.ToString()))
        Next

        Return str.ToString()
    End Function

End Class
